namespace Yaaf.WP7.NativeAccess.Helper
{
    public abstract class AccessManager<T> where T : class
    {
        public static T Access
        {
            get
            {
                return Instance.InstanceAccess;
            }
        }
        public static bool IsAvailable
        {
            get
            {
                return Instance.InstanceIsAvailable;
            }
        }

        public static AccessManager<T> Instance { get; protected set; }
        protected AccessManager()
        {
            InstanceIsAvailable = false;
        }

        protected internal void Initialize()
        {
            var accessFromDevice = GetAccessFromDevice(DeviceSwitcher.DeviceType);
            InstanceAccess = accessFromDevice;
            InstanceIsAvailable = accessFromDevice != null;
        }

        public T InstanceAccess { get; protected internal set; }
        public bool InstanceIsAvailable { get; protected internal set; }

        protected internal static void SwitchAccess(T newAccess)
        {
            Instance.InstanceAccess = newAccess;
            Instance.InstanceIsAvailable = newAccess != null;
        }

        protected abstract T GetAccessFromDevice(DeviceManufacturer manufacturer);
    }
}